package com.dykj.fireFighting.web.service.impl;/**
 * Created by admin on 2019-8-16.
 */

import com.dykj.fireFighting.web.service.WebsocketService;
import com.dykj.fireFighting.web.webSocket.WebSocketServer;

import com.dykj.fireFighting.api.base.system.entity.SysUser;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @author LiChunHua
 * @date 2019-8-16
 */
@Service
public class WebsocketServiceImpl implements WebsocketService {

    //@Autowired
    //private WebsocketMapper websocketMapper;

    @Override
    public int pushToWeb(String message, List<SysUser> allContacts, String type, String url, String goCode) {
        /*List<SysUser> list =new ArrayList<>();*/
        for(SysUser sysUser : allContacts){
            String message1="";
            message1 = message+"#"+type+"#"+url+"#"+goCode;
            String code = Long.toString(sysUser.getId());
            try {
                boolean b = WebSocketServer.sendInfo(message1, code);
                if(b){
                    return 1;
                    /*list.add(sysUser);
                    String name = sysUser.getUserName();
                    Map<String, Object> params = new HashMap<>();
                    Date date = new Date();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                    params.put("code", UUIDUtils.get32UUID());
                    params.put("time",dateFormat.format(date));
                    params.put("message", message);
                    params.put("name", name);
                    //websocketMapper.insert(params);*/
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

       /* Map<String, Object> params = new HashMap<>();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        params.put("code", UUIDUtils.get32UUID());
        params.put("time",dateFormat.format(date));
        params.put("message", message);
        params.put("list", list);
       if(list.size()==0){
           return  0;
       }else {
           return websocketMapper.insert(params);
       }*/
       return 0;
    }
}
